package com.chenc.javathreads.controlleraop.filter;

import com.chenc.javathreads.controlleraop.config.RequestWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author 01
 * @program wrapper-demo
 * @description 替换HttpServletRequest

 * @create 2018-12-24 21:04
 * @since 1.0
 **/
@Slf4j
@Component
public class ReplaceStreamFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
//        log.info("StreamFilter初始化...");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        ServletRequest requestWrapper = new RequestWrapper((HttpServletRequest) request);
//        ServletResponse responseWrapper = new ResponseWrapper((HttpServletResponse) response);
        chain.doFilter(requestWrapper, response);
    }

    @Override
    public void destroy() {
//        log.info("StreamFilter销毁...");
    }
}
